package cn.Mmovie.servlet;

import cn.Mmovie.bean.Cinema;
import cn.Mmovie.service.CinemaService;
import cn.Mmovie.service.impl.CinemaServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminModifyCinemaServlet", value = "/admin/modify_cinema")
public class AdminModifyCinemaServlet extends HttpServlet {
    private CinemaService cinemaService=new CinemaServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("-------ModifyCinema----------");
        request.setCharacterEncoding("utf-8");
        Integer id=Integer.parseInt(request.getParameter("id"));
        String name=request.getParameter("cinema_name");
        String location=request.getParameter("location");
        Integer capacity=Integer.parseInt(request.getParameter("capacity"));

        Cinema cinema=new Cinema(id,name,location,capacity);
        Integer result=cinemaService.modifyCinema(cinema);
        if (result>0){
            request.setAttribute("msg","电影院信息修改成功！");
            request.getRequestDispatcher("/admin/cinema_list").forward(request,response);
        }else if (result==-1){
            request.setAttribute("failMsg","需要修改的电影院不存在！");
            request.getRequestDispatcher("/admin/cinema_list").forward(request,response);
        }else {
            request.setAttribute("failMsg","电影院信息修改失败，请重试！");
            request.getRequestDispatcher("/admin/cinema_list").forward(request,response);
        }
    }
}
